package com.lemon.smartsafetynew.ui.fragment.device;

import android.os.Bundle;

import com.lemon.android.http.LemonRequestParams;
import com.lemon.smartsafety.app.RefreshType;
import com.lemon.smartsafety.listener.RecyclerTClickListener;
import com.lemon.smartsafetynew.ui.fragment.base.BasePullToRefreshFragment;
import com.lemon.smartsafety.utils.app.UIHelper;
import com.lemon.smartsafetynew.entity.device.DeviceVo;
import com.lemon.smartsafetynew.net.services.DeviceServices;
import com.lemon.smartsafetynew.ui.activity.device.DeviceDetailActivity;
import com.lemon.smartsafetynew.ui.adapter.device.DeviceListAdapter;
import com.lemon.smartsafetynew.util.constants.KeyConstants;
import com.lemon.smartsafetynew.util.user.AccountUtil;

import java.util.List;

import kale.adapter.LemonRcvAdapter;

/**
 * Created by Andrew on 2017/9/15.
 */

public class DeviceListFragment extends BasePullToRefreshFragment<DeviceVo, List<DeviceVo>>
        implements RecyclerTClickListener<DeviceVo> {

    public static DeviceListFragment newInstance() {

        Bundle args = new Bundle();

        DeviceListFragment fragment = new DeviceListFragment();
        fragment.setArguments(args);
        return fragment;
    }

    @Override
    public void onPullRefresh() {
        LemonRequestParams params = new LemonRequestParams("");
        params.put("company_id", AccountUtil.getCompanyId());
        params.put("pageNum", currentPage);
        params.put("pageSize", pageSize);
        DeviceServices
                .init()
                .getDeviceList(RefreshType.REFRESH, params);
    }

    @Override
    public void onLoadMore() {
        LemonRequestParams params = new LemonRequestParams("");
        params.put("company_id", AccountUtil.getCompanyId());
        params.put("pageNum", currentPage);
        params.put("pageSize", pageSize);
        DeviceServices
                .init()
                .getDeviceList(RefreshType.LOAD_MORE, params);
    }

    @Override
    public boolean goRefreshOnCreate() {
        return true;
    }

    @Override
    public LemonRcvAdapter<DeviceVo> getLemonAdapter() {
        return new DeviceListAdapter(mDataList, this);
    }

    @Override
    public String getHttpTag() {
        return KeyConstants.URL_GET_DEVICE_LIST;
    }

    @Override
    protected void initViews() {
        super.initViews();
    }

    @Override
    public void onItemClick(DeviceVo data, int position) {

        Bundle bundle = new Bundle();
        bundle.putSerializable(KeyConstants.KEY_DEVICE_VO, data);
        UIHelper.showActivity(getmContext(), bundle, DeviceDetailActivity.class);

    }


}
